<?php


namespace app\mini\controller\v1\shop;

use app\common\library\MemberVo;
use app\common\logic\ShopGoodsLogic;
use app\mini\controller\Common;
use think\Request;
use think\response\Json;

class ShopGoods extends Common
{
    public $ShopGoodsLogic;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->ShopGoodsLogic = new ShopGoodsLogic();
    }

    /**
     * 产品列表
     * @return Json
     */
    public function lists(): Json
    {
        $res = $this->exception(function () {
            return $this->ShopGoodsLogic->lists(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 产品上架
     * @return Json
     */
    public function putAway(): Json
    {
        $res = $this->exception(function () {
            return $this->ShopGoodsLogic->putAway(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 产品下架
     * @return Json
     */
    public function soldOut(): Json
    {
        $res = $this->exception(function () {
            return $this->ShopGoodsLogic->soldOut(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 产品详情
     * @return Json
     */
    public function detail(): Json
    {
        $res = $this->exception(function () {
            $params = request()->param();
            $params['shop_id'] = MemberVo::instance()->getShopId();
            return $this->ShopGoodsLogic->info($params);
        });
        return $this->response($res);
    }

    /**
     * 产品排序
     * @return Json
     */
    public function sort(): Json
    {
        $res = $this->transException(function () {
            return $this->ShopGoodsLogic->sort(request()->param());
        });
        return $this->response($res);
    }

}